import java.util.Stack;


//获取最小值的栈
public class MyStact {
    Stack<Integer> stack;
    Stack<Integer> minStack;

    public MyStact(){
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(!minStack.isEmpty()) {
            minStack.push(val);
        }else {
            int peekMinVal = minStack.peek();
            if(val <= peekMinVal) {
                minStack.push(val);
            }
        }
    }
    public void pop(){
        int val = stack.pop();

        if(val == minStack.peek()) {
            minStack.pop();
        }
    }
    public int getMin(){
        return minStack.peek();
    }
}
